from evaluate.models import StuentEnvironment as s_e 
from evaluate.jsonTools import studentJson
from evaluate.models import StudentHot,Function
from evaluate.models import StudentEnvironmentOrganization,TeacherEnvironmentOrganization
import time

#学生学期总评
def Term_freshair(data_type):
	term_list = Function.objects.filter(state='end').order_by('-id')[:2]
	total_on = s_e.objects.filter(year_term=term_list[0].year_term,environment_type=data_type)[0] #最近完成，学生总体评价数据
	total_ago = s_e.objects.filter(year_term=term_list[1].year_term,environment_type=data_type)[0] #最近次年完成，学生总体评价数据
	student_hot = StudentHot.objects.filter(year_term=term_list[0].year_term,environment_type=data_type)[0] #学生热词
	option_s_total=studentJson.pieJson(total_on,term_list[0].year_term)  #总体，饼图
	option_now_ago =  studentJson.now_ago_line(total_on,total_ago)#往年比较
	option_w_hot = studentJson.hot_word(student_hot)
	
                    
	data_dict={'总体饼图':option_s_total,'总体往年对比':option_now_ago,'总体热词':option_w_hot}
	return data_dict

#学生对校内机构的评价
def st_organization_total(e_type):
	term_list= Function.objects.filter(state='end').order_by('-id')[:2]
	if e_type=='student':
		org_now = StudentEnvironmentOrganization.objects.get(year_term=term_list[0].year_term)
		org_ago = StudentEnvironmentOrganization.objects.get(year_term=term_list[1].year_term)
	else:
		org_now = TeacherEnvironmentOrganization.objects.get(year_term=term_list[0].year_term)
		org_ago = TeacherEnvironmentOrganization.objects.get(year_term=term_list[1].year_term)
	option_org = studentJson.org_pie(org_now)
	option_now_ago = studentJson.org_now_ago(org_now,org_ago)
	data_dict={'总体饼图':option_org,'总体往年对比':option_now_ago,}
	return data_dict